<!DOCTYPE html>
<html>

  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">用户管理</a>
        <a>
          <cite>用户列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);"
        title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <xblock>
        <button id="delAll" class="layui-btn layui-btn-danger"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="x_admin_show('添加用户','./user-add.html',600,440)"><i class="layui-icon"></i>添加</button>
        <span id="total" class="x-right" style="line-height:40px"></span>
      </xblock>

      <table class="layui-table" id="layui_table_id" lay-filter="dataTable1"></table>

    </div>

    <script type="text/html" id="admin">
      {{# if(d.admin == 0){ }}
        普通用户
      {{# }else{ }}
        管理员
      {{# } }}
    </script>
    
    <script type="text/html" id="operate">
       <a onclick="x_admin_show('修改密码','user-password.html?userUUID={{d.userUUID}}&userPassword={{d.userPassword}}',600,400)" title="修改密码" href="javascript:;">
        <i class="layui-icon">&#xe642;</i>
      </a>
      {{# if(d.userUUID != "32b3d188a504438f8d867bc86afbdeb7") { }}
        <a title="删除" onclick="user_del('{{d.userUUID}}')" href="javascript:;">
          <i class="layui-icon">&#xe640;</i>
        </a>
      {{# } }}
    </script>

    <script>
      layui.use('table', function() {
        var table = layui.table;
        //第一个实例
        table.render({
          id: "dataTable1",
          elem: '#layui_table_id',
          height: 448,
          url: '/user/getUsersList', //数据接口
          page: true,
          limit: 10,
          contentType: "application/x-www-form-urlencoded",
          method: 'post',
          cols: [
            [ //表头
              {
                checkbox: true
              }, {
                field: 'userName',
                title: '账户名称',
                width: 250,
                align: 'center',
                sort: true
              }, {
                field: 'userRegTime',
                title: '注册时间',
                width: 280,
                align: 'center',
                sort: true
              }, {
                field: 'userLoginTime',
                title: '登录时间',
                width: 280,
                align: 'center',
                sort: true
              }, {
                field: 'admin',
                title: '用户角色',
                width: 250,
                align: 'center',
                templet: '#admin'
              }, {
                title: '操作',
                width: 160,
                align: 'center',
                templet: '#operate'
              }
            ]
          ],
          done: function(res, curr, count) {
            $("#total").html("共有数据：" + count + " 条");
          }
        });
        
        $('#delAll').click(function() {
          layer.confirm('确认要删除选中的用户吗？', function() {
            var checkStatusData = table.checkStatus('dataTable1').data;
            for(var i = 0; i < checkStatusData.length; i++) {
              if(checkStatusData[i].userUUID != "32b3d188a504438f8d867bc86afbdeb7") {
                delAllUser(checkStatusData[i].userUUID);
              }
            }
            window.location.reload();
          });
        });

      });

      /*用户-删除*/
      function user_del(userUUID) {
        layer.confirm('确认要删除吗？', function() {
          $.ajax({
            method: "POST",
            url: "/user/delUserByUserUUID",
            data: {
              userUUID: userUUID
            }, //提交表单的数据
            success: function(res) {
              window.location.reload();
            },
            error: function() {
              layer.close(loading);
              layer.msg('操作失败', {
                icon: 2
              });
            }
          });
        });
      }
      
      function delAllUser(userUUID) {
        $.ajax({
          method: "POST",
          url: "/user/delUserByUserUUID",
          data: {
            userUUID: userUUID
          }, //提交表单的数据
          success: function(res) {},
          error: function() {
            layer.msg('操作失败', {
              icon: 2
            });
          }
        });
      }
      
    </script>
  </body>

</html>
